package com.example.sys.ai.service.impl;

import com.example.core.utils.SpringBeanUtils;
import com.example.sys.ai.service.SysAiHandler;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

public abstract class AbstractSysAiHandler implements SysAiHandler {

    public static final String AI_TOKEN = "_AI_API_TOKEN_KEY_";

    public static final String TOKEN_KEY = "access_token";

    public static final String EXPIRES_IN = "expires_in";

    private ApplicationContext applicationContext;

    private RedisTemplate<String, String> redisTemplate;

    @Override
    public RedisTemplate<String, String> getRedisTemplate() {
        if (this.redisTemplate == null) {
            this.redisTemplate = getApplicationContext().getBean(StringRedisTemplate.class);
        }
        return this.redisTemplate;
    }

    @Override
    public ApplicationContext getApplicationContext() {
        if (this.applicationContext == null) {
            this.applicationContext = SpringBeanUtils.getApplicationContext();
        }
        return this.applicationContext;
    }
}
